{% extends 'envs_python/layout_envs_python.html' %}
{% load static %}
{% load foundation_tags %}

{% block panel_js_files %}
<script src="{% static 'js/sharedkit.js' %}"></script>
{% endblock %}

{% block html_js_code %}
{{ block.super }}
<script>
layui.use(function(){
  var layer = layui.layer;
  var util = layui.util;

  // 事件绑定
  util.on('lay-on', {
    "open_explorer": function(obj){
        var url = obj.data('url');
        openFolder(url);
        return false;
    },
    "openTerminal": function(obj){
        var url = obj.data('url');
        openTerminal(url);
        return false;
    },
      "copy-full-path-btn": function(obj){
          var fullPath = obj.data('path');
          copyToClipboard(fullPath);
          return false;
      }
  });
});
</script>
{% endblock %}

{% block page_content %}
{{ block.super }}
{% include 'include_messages.html' %}
<div class="card">
    <div class="card-header p-2">
        <div class="card-title">
<a href="{% url 'envs_python_runtime:versions_list' %}" class="btn bg-success">
  <i class="fas fa-plus"></i> 安装
</a>
<a href="{% url 'envs_python_runtime:import' %}" class="btn bg-success"><i class="fas fa-file-import"></i> 导入</a>
        </div>
        <div class="card-tools pr-2">
<a href="{% url 'envs_python_runtime:default_reset' %}"
   class="btn btn-outline-info"><i class="far fa-window-restore"></i> 重置默认</a>
<a href="{% url 'envs_python_runtime:config' %}" class="btn btn-outline-info"><i class="fas fa-cog"></i>  配置安装</a>
<a href="{% url 'envs_python_runtime:clearcache' %}" class="btn btn-outline-info">
    <i class="fas fa-trash"></i> 清理下载缓存
</a>
        </div>
    </div>
    <div class="card-body p-2">
        <table class="table table-hover table-striped">
            <thead>
                <tr>
                    <th>名称</th>
                    <th>版本</th>
                    <th>默认</th>
                    <th>解释器路径</th>
                    <th></th>
                </tr>
            </thead>
            <tbody>
{% for uuid, version in python_list.items %}
                <tr{% if version.folder == default_env_python.path %} class="table-success"{% endif %}>
                    <td>{{ is_path }}
{% if not version.is_path %}<i class="fas fa-exclamation text-danger" title="路径异常"></i>{% endif %}
 {% if version.name %}{{ version.name|default_if_none:"-" }}{% else %}{{ version.version }}{% endif %}
                    </td>
                    <td>{{ version.version_major }}.{{ version.version_minor }}.{{ version.version_patch }}</td>
                    <td>
{% if version.folder == default_env_python.path %}默认{% else %}-{% endif %}
                    </td>
                    <td>
<button class="btn btn-outline-secondary btn-xs"
        data-url="{% url 'sharedkit:open_explorer' %}?path={% replace_str version.folder '\\' '/' %}"
        title="打开文件夹" lay-on="open_explorer">
    <i class="far fa-folder-open"></i>
</button>
<button class="btn btn-outline-secondary btn-xs" data-path="{% replace_str version.folder '/' '\\' %}python.exe"
        title="复制完整路径"  lay-on="copy-full-path-btn">
    <i class="far fa-copy"></i>
</button>
<button type="button" data-url="{% url 'sharedkit:open_terminal' %}?path={{ version.folder }}"
        class="btn btn-outline-secondary btn-xs" title="打开终端命令行" lay-on="openTerminal">
    <i class="fa fa-terminal fa-xs"></i>
</button>
{% replace_str version.folder '/' '\\' %}python.exe
                    </td>
                    <td>
{% if version.is_path %}
<a href="{% url 'envs_python_runtime:default_set' uuid %}"
   class="btn btn-outline-info btn-xs{% if version.folder == default_env_python.path %} disabled{% endif %}">默认</a>
<a href="{% url 'envs_python_runtime:package_list' uuid %}" class="btn btn-outline-info btn-xs{% if not version.is_path %} disabled{% endif %}">包管理</a>
<a href="{% url 'envs_python_runtime:name_edit' uuid %}" class="btn btn-outline-info btn-xs">名称</a>
<a href="{% url 'envs_python_runtime:uninstall' uuid %}" class="btn btn-outline-info btn-xs">卸载</a>
{% endif %}
<a href="{% url 'envs_python_runtime:delete' %}?uuid={{ uuid }}" class="btn btn-outline-info btn-xs"
   onclick="return confirm('仅删除配置信息，实际环境您还可以使得导入功能重新导入。\r\n确定要删除吗？');">删除</a>

                     </td>
                </tr>
{% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}